﻿/*********************************************************************************
 *Author:         OnClick
 *Version:        1.0
 *UnityVersion:   2018.3.1f1
 *Date:           2019-03-26
 *Description:    IFramework
 *History:        2018.11--
*********************************************************************************/
using System;

namespace IFramework
{
    public class AccessInfo : BaseInfo
    {
        public string Host { get; set; }// 连接主机
        public string Origin { get; set; }// 连接源
        public string SecWebSocketKey { get; set; }// 安全密钥
        public string SecWebSocketVersion { get; set; }// 安全版本
        public string SecWebSocketExtensions { get; set; }// 安全扩展
        public bool IsHandShaked { get { return !string.IsNullOrEmpty(SecWebSocketKey); } }
        public override string ToString()
        {
            if (string.IsNullOrEmpty(HttpProto))
                HttpProto = "GET / HTTP/1.1";
            if (string.IsNullOrEmpty(SecWebSocketVersion))
                SecWebSocketVersion = "13";
            return string.Format("{0}{1}{2}{3}{4}{5}{6}",
                HttpProto + Environment.NewLine, "Host: " + Host + Environment.NewLine,
                "Connection: " + Connection + Environment.NewLine, "Upgrade: " + Upgrade + Environment.NewLine,
                "Origin: " + Origin + Environment.NewLine,
                "Sec-WebSocket-Version: " + SecWebSocketVersion + Environment.NewLine,
                "Sec-WebSocket-Key: " + SecWebSocketKey + Environment.NewLine + Environment.NewLine);
        }
    }
}
